home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.4 / AppShell / Examples / Support / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  5.0 KB  |  156 lines

  1. /************************************************************************
  2.  *                                                                      *
  3.  *                            Preliminary                               *
  4.  *                        Amiga AppShell (tm)                           *
  5.  *                                                                      *
  6.  *  Copyright (c) 1990,1991 Commodore-Amiga, Inc. All Rights Reserved.  *
  7.  *                                                                      *
  8.  *   This software and information is proprietary, preliminary, and     *
  9.  *   subject to change without notice.                                  *
  10.  *                                                                      *
  11.  *                            DISCLAIMER                                *
  12.  *                                                                      *
  13.  *   THIS SOFTWARE IS PROVIDED "AS IS".                                 *
  14.  *   NO REPRESENTATIONS OR WARRANTIES ARE MADE WITH RESPECT TO THE      *
  15.  *   ACCURACY, RELIABILITY, PERFORMANCE, CURRENTNESS, OR OPERATION      *
  16.  *   OF THIS SOFTWARE, AND ALL USE IS AT YOUR OWN RISK.                 *
  17.  *   NEITHER COMMODORE NOR THE AUTHORS ASSUME ANY RESPONSIBILITY OR     *
  18.  *   LIABILITY WHATSOEVER WITH RESPECT TO YOUR USE OF THIS SOFTWARE.    *
  19.  *                                                                      *
  20.  *                          Non-Disclosure                              *
  21.  *                                                                      *
  22.  *   This information is not to be disclosed to any other company,      *
  23.  *   individual or party.  Discussion is to be restricted to CBM        *
  24.  *   approved discussion areas, such as the closed conferences on bix;  *
  25.  *   amiga.cert, amiga.com, amiga.beta/appshell.                        *
  26.  *                                                                      *
  27.  ************************************************************************
  28.  * Copyright (C) 1990,1991 Commodore-Amiga, Inc.
  29.  * written by David N. Junod
  30.  */
  31.  
  32. #include <exec/types.h>
  33. #include <exec/libraries.h>
  34. #include <intuition/intuition.h>
  35. #include <libraries/appshell.h>
  36. #include <workbench/startup.h>
  37. #include <clib/alib_protos.h>
  38. #include <clib/exec_protos.h>
  39. #include <clib/intuition_protos.h>
  40. #include <clib/appshell_protos.h>
  41. #include <pragmas/appshell_pragmas.h>
  42. #include <string.h>
  43.  
  44. struct Library *AppShellBase;
  45.  
  46. static struct TextAttr T80 = {"topaz.font", 8, NULL, NULL};
  47. static struct IntuiText T0 = {2,1,JAM2,20,24,&T80,"Requires appshell.library",NULL};
  48. static struct IntuiText T1 = {0,1,JAM2,20,10,&T80,NULL,&T0};
  49. static struct IntuiText T2 =
  50. {
  51.     AUTOFRONTPEN, AUTOBACKPEN, AUTODRAWMODE, AUTOLEFTEDGE,
  52.     AUTOTOPEDGE, &T80, " OK ", NULL
  53. };
  54.  
  55. extern char *_ProgramName;
  56.  
  57. static VOID RequiresAppShell(VOID)
  58. {
  59.     extern struct Library *IntuitionBase;
  60.     char buffer[80];
  61.  
  62.     /* Open Intuition, so that we can bring up an AutoRequest */
  63.     if (IntuitionBase = OpenLibrary ("intuition.library", 0))
  64.     {
  65.     /* Copy the name of the application into the buffer.  This is
  66.      * SAS specific. */
  67.     memcpy (buffer, _ProgramName, (long) _ProgramName[-1]);
  68.     buffer[(int)_ProgramName[-1]] = '\0';
  69.     T1.IText = buffer;
  70.  
  71.     /* Display the error message */
  72.     AutoRequest (NULL, &T1, NULL, &T2, 0, 0, 320, 60);
  73.     }
  74. }
  75.  
  76. #define    MY_OWN_HOOK    FALSE
  77.  
  78. #if MY_OWN_HOOK
  79.  
  80. /* This is an example of how to define your own hook */
  81. VOID __asm newdispatchHook (
  82.     register __a0 struct Hook * h,
  83.     register __a2 struct AppInfo *ai,
  84.     register __a1 struct AppFunction *af)
  85. {
  86.     VOID (* __asm func)(
  87.     register __a0 struct Hook *,
  88.     register __a2 struct AppInfo *,
  89.     register __a1 struct AppFunc *);
  90.  
  91.     func = h->h_SubEntry;
  92.     (*func)(h, ai, af);
  93. }
  94.  
  95. /* Application initialization and startup */
  96. VOID main (int argc, char **argv)
  97. {
  98.     extern struct WBStartup *WBenchMsg;
  99.     extern struct TagItem Our_App[];
  100.     struct TagItem tag[3];
  101.  
  102.     /* open the AppShell library */
  103.     if (AppShellBase = OpenLibrary ("appshell.library", 36))
  104.     {
  105.     struct Hook hook;
  106.  
  107.     hook.h_Entry = newdispatchHook;
  108.  
  109.     tag[0].ti_Tag = APSH_DispatchHook;
  110.     tag[0].ti_Data = &hook;
  111.     tag[1].ti_Tag = TAG_MORE;
  112.     tag[1].ti_Data = (ULONG) Our_App;
  113.  
  114.     /* Main AppShell entry point */
  115.     HandleApp (argc, argv, WBenchMsg, tag);
  116.  
  117.     /* close the AppShell library */
  118.     CloseLibrary (AppShellBase);
  119.     }
  120.     else
  121.     {
  122.     RequiresAppShell();
  123.     }
  124. }
  125.  
  126. #else
  127.  
  128. /* Application initialization and startup */
  129. VOID main (int argc, char **argv)
  130. {
  131.     extern struct WBStartup *WBenchMsg;
  132.     extern struct TagItem Our_App[];
  133.     struct TagItem tag[3];
  134.  
  135.     /* open the AppShell library */
  136.     if (AppShellBase = OpenLibrary ("appshell.library", 36))
  137.     {
  138.     /* Tell the AppShell that we understand new-style functions */
  139.     tag[0].ti_Tag = APSH_HookClass;
  140.     tag[0].ti_Data = TRUE;
  141.     tag[1].ti_Tag = TAG_MORE;
  142.     tag[1].ti_Data = (ULONG) Our_App;
  143.  
  144.     /* Main AppShell entry point */
  145.     HandleApp (argc, argv, WBenchMsg, tag);
  146.  
  147.     /* close the AppShell library */
  148.     CloseLibrary (AppShellBase);
  149.     }
  150.     else
  151.     {
  152.     RequiresAppShell();
  153.     }
  154. }
  155. #endif
  156.